﻿using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Catalyst.ServiceModelZero;

namespace Catalyst.ServiceModel
{
	public class PingProxy : CloudProxy<PingProxy, IPing>
	{
		public static bool Ping(Binding binding = null, EndpointAddress endpointAddress = null)
		{
			IPing proxy = null;
			bool isOnline = false;

			//try
			//{
			//    proxy = CloudChannelFactory<IPing>.CreateChannel(binding, endpointAddress);

			//    isOnline = proxy.Ping();
			//}
			//catch
			//{
				
			//}
			//finally
			//{
			//    if (proxy != null)
			//    {
			//        (proxy as ICommunicationObject).Close();
			//    }
			//}

			try
			{
				proxy = CreateChannel(binding, endpointAddress);
				isOnline = proxy.Ping();
			}
			catch
			{
				Abort(proxy);
				throw;
			}
			finally
			{
				CloseChannel(proxy);
			}
			
			return isOnline;
		}

		protected override Binding GetBinding()
		{
			throw new NotImplementedException();
		}

		protected override EndpointAddress GetEndpointAddress()
		{
			throw new NotImplementedException();
		}
	}
}
